package com.vcredit.creditcat.manager.product;

import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.alibaba.dubbo.config.annotation.Service;
import com.vcredit.creditcat.api.IProductApplyManager;
import com.vcredit.creditcat.bean.SpringContextHolder;
import com.vcredit.creditcat.dto.product.BlackParamDto;
import com.vcredit.creditcat.dto.product.CreditSubmitDto;
import com.vcredit.creditcat.dto.product.ProductDecisionResultDto;
import com.vcredit.creditcat.exception.ProductCanNotApplyException;
import com.vcredit.creditcat.model.CustProductApply;
import com.vcredit.creditcat.service.product.CreditCommonApplyService;
import com.vcredit.creditcat.service.product.IProductApplyService;
import com.vcredit.framework.annotation.Log;

/**
 * @author 张新功
 */
@Service(protocol = { "protocol1" }, version = "1.0")
public class ProductApplyManager implements IProductApplyManager, InitializingBean {
	@Autowired
	public CreditCommonApplyService creditCommonApplyService;

	@Log
	@Override
	@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
	public void noticeApplyResult(CustProductApply resultDto, String productName) throws Exception {
		// 产品独立处理
		creditCommonApplyService.saveCustProductApply(resultDto);
	}

	@Log
	@Override
	public ProductDecisionResultDto computeAuditResult(String productName, CreditSubmitDto paramDto) throws Exception {
		IProductApplyService applyService = (IProductApplyService) SpringContextHolder.getBean(productName);
		// return applyService.computeAuditResult(paramDto);
		return null;
	}

	@Log
	@Override
	public ProductDecisionResultDto queryAuditResult(String productName, String identityNo) throws Exception {
		IProductApplyService applyService = (IProductApplyService) SpringContextHolder.getBean(productName);
		// return applyService.queryAuditResult(identityNo);
		return null;
	}

	@Log
	@Override
	public Boolean canApply(String productName, BlackParamDto paramDto) throws ProductCanNotApplyException, Exception {
		IProductApplyService applyService = (IProductApplyService) SpringContextHolder.getBean(productName);
		// return applyService.canApply(paramDto);
		return null;
	}

	/**
	 * 这个方法将在所有的属性被初始化后调用。 但是会在init前调用。 @Lazy(false) 但是主要的是如果是延迟加载的话，则马上执行。
	 */
	@Override
	public void afterPropertiesSet() throws Exception {

	}

}
